package com.wa.bean;

import java.util.Date;

import com.wa.dto.OperatorInfoDto;
import com.wa.enums.LogModuleEnum;
import com.wa.enums.LogPlatformEnum;
import com.wa.enums.LogTypeEnum;
import com.wa.pojo.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 平台日志
 * @Author Dawn
 * @Date 2021/10/18 14:43
 */
@Data
@EqualsAndHashCode(callSuper=true)
@AllArgsConstructor
@NoArgsConstructor
public class BasicAllchipsLog extends BaseEntity {
    /**
    * 日志id
    */
    private Long id;

    /**
    * 平台类型
    */
    private Integer platform;

//    @NotEntityFiled
    private String platformCN;

    /**
    * 功能模块
    */
    private Integer module;
//    @NotEntityFiled
    private String moduleCN;

    /**
    * 日志类型
    */
    private Integer type;
//    @NotEntityFiled
    private String typeCN;

    /**
     * 日志种类
     */
//    @NotEntityFiled
    private Integer logCategory;
    /**
    * 描述
    */
    private String desc;

    /**
    * 更新前
    */
    private String before;

    /**
    * 更新后
    */
    private String after;

    /**
     * 收件人
     */
    private String receiver;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
    * 操作实体id
    */
    private Long entityId;

    /**
    * 操作实体名称
    */
    private String entityName;

    /**
     * 操作实体关键字
     */
//    @NotEntityFiled
    private String entityKeyword;

    /**
    * 创建用户id
    */
    private Integer createUserId;

    /**
    * 创建用户邮箱
    */
    private String createUserEmail;

    /**
    * 创建用户名
    */
    private String createUserName;

    /**
    * 创建时间
    */
    private Date createTime;

    /**
    * 创建ip
    */
    private String createIp;

    /**
     * 表名
     */
//    @NotEntityFiled
    private String tableName;
    /**
     * 时间查询
     */
    private String startTime;
    private String endTime;

    public BasicAllchipsLog(OperatorInfoDto operatorInfoDto) {
        if (operatorInfoDto != null) {
            this.createUserId = operatorInfoDto.getCreateUserId();
            this.createUserEmail = operatorInfoDto.getCreateUserEmail();
            this.createUserName = operatorInfoDto.getCreateUserName();
            this.createTime = operatorInfoDto.getCreateTime();
            this.createIp = operatorInfoDto.getCreateIp();
        }
        if (this.createTime == null) {
            this.createTime = new Date();
        }
    }

    public void setPlatform(Integer platform) {
        if(null!= LogPlatformEnum.get(platform)){

            this.platformCN = LogPlatformEnum.get(platform).getStatusMsgCn();
        }
        this.platform = platform;
    }

    public void setModule(Integer module) {

        if(null!= LogModuleEnum.get(module)){

            this.moduleCN = LogModuleEnum.get(module).getStatusMsgCn();
        }
        this.module = module;
    }

    public void setType(Integer type) {
        if(null!= LogTypeEnum.get(type)){

            this.typeCN = LogTypeEnum.get(type).getStatusMsgCn();
        }
        this.type = type;
    }
}